package com.hljx.job;

import cn.hutool.json.JSONUtil;
import com.hljx.entity.AdviceItem;
import com.hljx.vo.AdviceItemVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.batch.core.configuration.annotation.StepScope;
import org.springframework.batch.item.ItemProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

/**
 * @BelongsProject: hljx
 * @BelongsPackage: com.hljx.job
 * @Author: lp
 * @CreateTime: 2023-10-25  08:40
 * @Description: TODO
 * @Version: 1.0
 */
@Slf4j
@Configuration
public class ProcessorItem {


    @StepScope
    @Bean(name = "adviceItemProcessor")
    public ItemProcessor<AdviceItem, AdviceItemVO> adviceItemProcessor() {
        return new ItemProcessor<AdviceItem, AdviceItemVO>() {
            @Override
            public AdviceItemVO process(AdviceItem item) throws Exception {
                // 在此处理读取到的 AdviceItem 数据，将其添加到列表
                AdviceItemVO adviceItemVO = new AdviceItemVO();
                List<AdviceItem> adviceItemList = new ArrayList<>();
                adviceItemList.add(item);
                adviceItemVO.setAdviceItemList(adviceItemList);
                log.info(String.valueOf(adviceItemList.size()));
                return adviceItemVO;

            }

        };

    }

}
